<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div>
  <ul id="userDropTree" class="ztree"
    style="margin: 0px; padding: 0; border: 0 solid white; background: #f0f6e4; overflow-y: hidden;"></ul>
</div>
<script type="text/javascript">
    require([ "dojo/_base/lang" ], function(lang) {
        var dropId = "${dropTree.dropId}";
        var cType = "${dropTree.cType}";
        var keyId = "${dropTree.keyId}";
        var beforeClick = function(treeId, treeNode) {
            var zTree = jQuery.fn.zTree.getZTreeObj(treeId);
            zTree.checkNode(treeNode, !treeNode.checked, null, true);
            return false;
        };
        var onCheck = function(e, treeId, treeNode) {
            var zTree = jQuery.fn.zTree.getZTreeObj(treeId);
            var nodes = zTree.getCheckedNodes(true), v = "", k = "";
            for ( var i = 0, l = nodes.length; i < l; i++) {
                v += nodes[i].username + ",";
                k += nodes[i].userId + ",";
            }
            if (v.length > 0) {
                v = v.substring(0, v.length - 1);
                k = k.substring(0, k.length - 1);
            }
            var dispObj = jQuery("#" + dropId);
            var realObj = jQuery("#" + keyId);
            dispObj.attr("value", v);
            realObj.attr("value", k);
        };
        var setting = {
            async : {
                enable : true,
                url : "sysuser/queryUserTree?username=" + username
            },
            check : {
                enable : true,
                chkStyle : "radio",
                radioType : "all"
            },
            view : {
                dblClickExpand : false
            },
            data : {
                key : {
                    name : 'username'
                },
                simpleData : {
                    enable : true,
                    idKey : 'userId'
                }
            },
            callback : {
                beforeClick : beforeClick,
                onCheck : onCheck
            }
        };
        if (cType.toUpperCase() == "M") {
            lang.mixin(setting, {
                check : {
                    enable : true,
                    chkboxType : {
                        "Y" : "",
                        "N" : ""
                    }
                }
            });
        }
        jQuery.fn.zTree.init(jQuery("#userDropTree"), setting);
    });
</script>